# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=tmux
_base_ver=2.9
_bugfix=.a
pkgver=${_base_ver}${_bugfix}
pkgrel=1
pkgdesc='A terminal multiplexer'
url='https://tmux.github.io/'
arch=('i686' 'x86_64')
license=('BSD')
conflict=('tmux-git')
replaces=('tmux-git')
depends=('ncurses' 'libevent')
makedepends=('ncurses-devel' 'libevent-devel')
source=(${pkgname}-${pkgver}.tar.gz::https://github.com/tmux/tmux/archive/${_base_ver}${_bugfix/./}.tar.gz
        'msys-platform.patch'
        'no-check-dirs-permission.patch'
        'inherit-msystem-var.patch')

sha256sums=('0d9cdebe9226d2745a46c018a01cd87aa996b32349335650afba638f42013f1c'
            'cf7e0f642d43fc97f7c55be41c693cceab5c891f81fcee687e918075e55cd533'
            '8f1938c9bcb99fba5441e11379a193c17eee582a03c04f1bde8089d58a84f44f'
            'cc832494d4fd4c7bd86a77af5f830422d342a812c890ef1d1d2e8d8a08352cd4')

prepare() {
  cd "${srcdir}/${pkgname}-${_base_ver}${_bugfix/./}"
  patch -p1 -i "${srcdir}"/msys-platform.patch
  patch -p0 -i "${srcdir}"/no-check-dirs-permission.patch
  patch -p1 -i "${srcdir}"/inherit-msystem-var.patch

  cp osdep-cygwin.c osdep-msys.c

  #msg2 "Running autogen.sh"
  ./autogen.sh
}

build() {
  cd "${srcdir}/${pkgname}-${_base_ver}${_bugfix/./}"
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    CPPFLAGS="${CPPFLAGS} -I/usr/include/ncursesw -U_XOPEN_SOURCE"
  make
}

package() {
  cd "${srcdir}/${pkgname}-${_base_ver}${_bugfix/./}"
  make DESTDIR="${pkgdir}" install

  install -d "${pkgdir}"/usr/share/licenses/tmux
  install -m 644 COPYING "${pkgdir}"/usr/share/licenses/tmux

  #install -d "${pkgdir}"/usr/share/tmux
  #install -m 644 examples/* "${pkgdir}"/usr/share/tmux
  #install -d "${pkgdir}"/usr/share/vim/vimfiles/syntax
  #install -m 644 examples/tmux.vim "${pkgdir}"/usr/share/vim/vimfiles/syntax

  #install -d "${pkgdir}"/usr/share/bash-completion/completions/tmux
  #mv "${pkgdir}"/usr/share/tmux/bash_completion_tmux.sh "${pkgdir}"/usr/share/bash-completion/completions/tmux
}
